package thread;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class ThreadTest2 implements Callable<String> {

    public static void main(String[] args) {
//        ThreadTest2 threadTest2 =new ThreadTest2();
//        FutureTask<String> futureTask =new FutureTask<String>(threadTest2);
//        new Thread(futureTask).start();

        ThreadTest2 threadTest2 =new ThreadTest2();
        FutureTask<String> task =new FutureTask<String>(threadTest2);
        Thread thread =new Thread(task);
        thread.start();




    }

    public String call() throws Exception {
        String method1 = this.method1();
        String method2 = this.method2();

        String result="";
        if(method1.equals("succ1")&& method2.equals("succ2")){
            result ="allSucc";
        }
        return result;
    }

    public String method1(){
        try {
            Thread.sleep(3000L);
            System.out.println("执行method1,线程名称"+Thread.currentThread().getName());
            for(int i =0;i<5;i++){
                System.out.println("执行method1====="+i);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "succ1";
    }

    public String method2(){
        try {
            //Thread.yield();
            System.out.println("执行method2,线程名称"+Thread.currentThread().getName());
            for(int i =0;i<5;i++){
                System.out.println("执行method2====="+i);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "succ2";
    }
}
